﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using System.Web;
using Antu.WorkFlowFactory;
using System.Data;

namespace WebSys.UI.OfficeFlow
{
    public class SuspendApplySkin : MPBasicTemplate
    {
        FlowFactoryProvider _FlowFactoryProvider = (FlowFactoryProvider)ProviderService.ProviderServiceMange.GetProvider("FlowFactoryProvider");
        Label lab_Msg, labIId, labType, labName, labWiid;
        TextBox txtMemo;
        protected string UserId
        {
            get
            {
                if (base.Page.Session["UserId"] != null)
                {
                    return base.Page.Session["UserId"].ToString();
                }
                else
                {
                    return string.Empty;
                }
            }
            set
            {
                base.Page.Session["UserId"] = value;
            }
        }
        protected override void OnLoad(EventArgs e)
        {
            InitControl();
            base.OnLoad(e);
            if (!base.Page.IsPostBack)
            {
                BindData();
            }
            Button btnOK = (Button)FindControl("btnOK");
            btnOK.Click += new EventHandler(btnOK_Click);
        }
        protected void InitControl() {
            lab_Msg = (Label)FindControl("lab_Msg");
            labIId = (Label)FindControl("labIId");
            labType = (Label)FindControl("labType");
            labName = (Label)FindControl("labName");
            labWiid = (Label)FindControl("labWiid");
            txtMemo = (TextBox)FindControl("txtMemo");
        }
        protected void BindData()
        {
            string striid = base.Page.Request["iid"];
            string strwiid = base.Page.Request["wiid"];
            labIId.Text = striid;
            labWiid.Text = strwiid;
            DataTable dt = _FlowFactoryProvider.GetWorkItemDT(striid, strwiid);
            if (dt.Rows.Count > 0)
            {
                labType.Text = dt.Rows[0]["wname"].ToString();
                labName.Text = dt.Rows[0]["name"].ToString();
            }
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            string iid = base.Page.Request.QueryString["iid"].ToString();
            string wiid = ((Label)FindControl("labWiid")).Text;
            string sumarry = ((TextBox)FindControl("txtMemo")).Text;
            string userid = UserId;
            if (!_FlowFactoryProvider.ApplySuspend(iid, wiid, userid, sumarry))
            {
                Antu.Utilities.UtilitiesPage.AlertDialog("申请挂起过程失败", "window.location.href=window.location.href;");
            }
            else {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "returnOk", "<script>returnOk();</script>");
            }
        }


    }
}


